const redirectInput = document.getElementById("redirect-input");
const strategyOptions = document.querySelectorAll(
  "input[name='strategyOption']"
);

chrome.storage.local.get(
  { redirectToVideo: false, navStrategy: "onBeforeNavigate" },
  (result) => {
    redirectInput.checked = result.redirectToVideo;

    strategyOptions.forEach((option) => {
      option.checked = option.value === result.navStrategy;
    });
  }
);

redirectInput.addEventListener("change", (event) => {
  chrome.storage.local.set({ redirectToVideo: event.target.checked });
});

strategyOptions.forEach((option) => {
  option.addEventListener("change", (event) => {
    const strategy = event.target.value;

    chrome.storage.local.set({ navStrategy: strategy });
  });
});
